package com.ynu.znkz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ynu.znkz.entity.PaperFocus;
import com.ynu.znkz.entity.PaperResearchProblem;
import com.ynu.znkz.mapper.PaperFocusMapper;
import com.ynu.znkz.service.PaperFocusService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lu
 * @since 2021-05-29
 */
@Service
public class PaperFocusServiceImpl extends ServiceImpl<PaperFocusMapper, PaperFocus> implements PaperFocusService {

    @Override
    public String savePaperFocus(String paperFocusName) {
        QueryWrapper<PaperFocus> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name",paperFocusName);
        List<PaperFocus> paperFoci = baseMapper.selectList(queryWrapper);

        //研究方法数据库中没有当前研究方法
        if(paperFoci.isEmpty()) {
            PaperFocus paperFocus = new PaperFocus();
            paperFocus.setName(paperFocusName);
            baseMapper.insert(paperFocus);
            return paperFocus.getId();
        }else
            return paperFoci.get(0).getId();
    }
}
